package com.zzyl.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 护理项目相关接口
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;

    // 分页查询护理项目
    @GetMapping
    @ApiOperation("分页查询护理项目")
    public ResponseResult<PageResponse> selectByPage(
            Integer pageNum,
            Integer pageSize,
            String name,
            Integer status// 状态：0：禁用，1：启用
    ) {
        return success(nursingProjectService.selectByPage(pageNum, pageSize, name, status));
    }

    // 新增护理项目
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult create(@ApiParam(value = "护理项目数据传输对象", required = true)
                                 @RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.saveProject(nursingProjectDto);
        return ResponseResult.success();
    }

    // 根据id删除护理项目
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理项目")
    public int removeById(@PathVariable Long id) {
        return nursingProjectService.removeById(id);
    }

    // 根据id修改护理项目
    @PutMapping
    @ApiOperation(value = "根据id修改护理项目")
    public ResponseResult updateById(@RequestBody NursingProjectDto nursingProjectDto) {
        BeanUtil.copyProperties(nursingProjectDto, NursingProject.class);
        nursingProjectService.updateById(nursingProjectDto);
        return ResponseResult.success();
    }

    // 根据id查询护理项目
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    // 启动或禁用
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启动项目/禁用项目")
    public ResponseResult isEnable(@PathVariable("id") Long id,@PathVariable("status") Integer status){
        nursingProjectService.isEnable(id,status);
        return success();
    }

    // 查询所有护理项目
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> selectAll() {

        return success(nursingProjectService.selectAll());
    }
}
